package com.chia.multienty.core.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chia.multienty.core.domain.dto.ProcessTypeDTO;
import com.chia.multienty.core.mapper.ProcessTypeMapper;
import com.chia.multienty.core.mybatis.MTLambdaWrapper;
import com.chia.multienty.core.mybatis.service.impl.KutaBaseServiceImpl;
import com.chia.multienty.core.parameter.workflow.*;
import com.chia.multienty.core.pojo.ProcessType;
import com.chia.multienty.core.service.ProcessTypeService;
import com.chia.multienty.core.util.ListUtil;
import com.github.yulichang.toolkit.MPJWrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 流程类型 服务实现类
 * </p>
 *
 * @author Multienty Auto Generator
 * @since 2024-05-31
 */
@Service
@RequiredArgsConstructor
public class ProcessTypeServiceImpl extends KutaBaseServiceImpl<ProcessTypeMapper, ProcessType> implements ProcessTypeService {


    @Override
    public ProcessTypeDTO getDetail(ProcessTypeDetailGetParameter parameter) {
        return selectJoinOne(ProcessTypeDTO.class,
                        MPJWrappers.<ProcessType>lambdaJoin().eq(ProcessType::getValue, parameter.getValue()));
    }

    @Override
    public void update(ProcessTypeUpdateParameter parameter) {
        ProcessType processType = new ProcessType();
        BeanUtils.copyProperties(parameter, processType);
        updateByIdTE(processType);
    }

    @Override
    public void delete(ProcessTypeDeleteParameter parameter) {
        removeByIdTE(parameter.getValue());
    }

    @Override
    public IPage<ProcessTypeDTO> getPage(ProcessTypePageGetParameter parameter) {
        return selectJoinListPage(parameter.getPageObj(), ProcessTypeDTO.class,
                new MTLambdaWrapper<ProcessType>()
                        .solveGenericParameters(parameter)
                        .in(!ListUtil.isEmpty(parameter.getValues()),
                                ProcessType::getValue,
                                parameter.getValues())
        );
    }

    @Override
    public List<ProcessType> getAll() {
        return list();
    }

    @Override
    public void save(ProcessTypeSaveParameter parameter) {
        ProcessType processType = new ProcessType();
        BeanUtils.copyProperties(parameter, processType);

        saveTE(processType);
        parameter.setValue(processType.getValue());
    }


}
